fastlane_version "2.120.0"

default_platform :ios

platform :ios do

  desc "Release a new version of KITPROJECT"
  lane :release do |options|
    # Ensure Git status is clean
    ensure_git_status_clean
    # Ensure Git branch is master
    ensure_git_branch(branch: 'master')
    # Perform Dependency-Manager compatibility tests
    compatibilityTests
    # Perform Tests
    tests
    # Retrieve Version from options
    version = options[:version]
    # Increment Version
    increment(version: version)
    # Add Git Tag
    add_git_tag(tag: version)
    # Push Git Tag
    push_git_tags()
    # Push Git commit
    push_to_git_remote()
    # Pod push / Pod trunk
    pod_push()
  end

  desc "Increment Version"
  lane :increment do |options|
    # Retrieve Version from options
    version = options[:version]
    # Set Podspec version
    version_bump_podspec(
      path: "KITPROJECT.podspec", 
      version_number: version
    )
    # Set Framework plist version
    set_info_plist_value(
      path: "Configs/KITPROJECT.plist", 
      key: "CFBundleShortVersionString", 
      value: version
    )
    # Set Framework Tests plist version
    set_info_plist_value(
      path: "Configs/KITPROJECTTests.plist", 
      key: "CFBundleShortVersionString", 
      value: version
    )
    # Set Example plist version
    set_info_plist_value(
      path: "Example/Resources/Info.plist", 
      key: "CFBundleShortVersionString", 
      value: version
    )
    # Commit modified files
    git_commit(
        path: [
          "KITPROJECT.podspec", 
          "Configs/KITPROJECT.plist", 
          "Configs/KITPROJECTTests.plist", 
          "Example/Resources/Info.plist"
        ],
        message: "KITPROJECT Version #{version} 🚀"
    )
  end

  desc "Runs tests"
  lane :tests do
    # Perform iOS Tests
    scan(
      project: "KITPROJECT.xcodeproj",
      scheme: "KITPROJECT-iOS",
      clean: true
    )
    # Perform tvOS Tests
    scan(
      project: "KITPROJECT.xcodeproj",
      scheme: "KITPROJECT-tvOS",
      clean: true
    )
    # Perform macOS Tests
    spm(command: "test")
    # Delete SPM build artifacts
    spm(command: "clean")
  end

  desc "Run Dependency-Manager compatibility tests"
  lane :compatibilityTests do
    # Pod lib lint to ensure CocoaPods compatibility
    pod_lib_lint(allow_warnings: true)
    # SPM Build to ensure Swift Package Manager compatibility
    spm(command: "build")
    # Delete SPM build artifacts
    spm(command: "clean")
  end

end
